<?php
class admin_listController extends adminController{

    
    //字段列表
    public function index()
    {
        $id=intval($_GET['id']);
        $this->alert_str($id,'int');
        $this->info=model('form')->info($id);
        $this->list=model('form_field')->field_list($id);
        $this->show();
    }

    public function field_data_check($data)
    {
        if(model('form_field')->field_info($data['field'],$data['fid'],$data['id'])){
            $this->msg('字段不能重复！',0);
        }
    }

    public function data_info()
    {
        $data['field_type']=api('expand_model','field_type');
        return $data;
    }

    //字段添加
    public function add()
    {
        $fid=intval($_GET['fid']);
        $this->alert_str($fid,'int');
        $this->view()->assign($this->data_info());
        $this->form_info=model('form')->info($fid); 
        $this->action_name='添加';
        $this->action='add';
        $this->show('admin_list/info');
    }

    public function add_save()
    {
        //录入模型处理
        $fid=intval($_POST['fid']);
        $this->alert_str($fid,'int',true);
        $this->field_data_check($_POST);
        model('form_field')->field_add($_POST);
        $this->msg('字段添加成功！',1);
    }

    //字段修改
    public function edit()
    {
        $id=intval($_GET['id']);
        $this->alert_str($id,'int');
        $this->view()->assign($this->data_info());
        $this->info=model('form_field')->field_info_id($id);
        $this->form_info=model('form')->info($this->info['fid']); 
        $this->action_name='编辑';
        $this->action='edit';
        $this->show('admin_list/info');
    }

    public function edit_save()
    {
        
        //录入模型处理
        $id=intval($_POST['id']);
        $this->alert_str($id,'int',true);
        $this->field_data_check($_POST);
        $id=model('form_field')->field_edit($_POST);
        $this->msg('字段修改成功！',1);
    }

    //字段删除
    public function del()
    {
        $id=intval($_POST['id']);
        $this->alert_str($id,'int',true);
        $fid=intval($_POST['fid']);
        $this->alert_str($fid,'int',true);
        //录入模型处理
        model('form_field')->field_del($_POST);
        $this->msg('字段删除成功！',1);

    }

}